package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {
    @Autowired
    private ICustomerTransferService transferService;
    @RequestMapping("/list")
    public String potentialList(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo pageInfo = transferService.query(qo);
        model.addAttribute("result",pageInfo);
        return "/customerTransfer/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTransfer customerTransfer){
        if(customerTransfer.getId() != null){
            transferService.update(customerTransfer);
        }else {
            transferService.save(customerTransfer);
        }
        return new JsonResult();
    }

}
